package ray;

import ray.math.Vector3;

public class OrthonormalBasis {

	protected Vector3 u = new Vector3(0,0,1);
	protected Vector3 v = new Vector3(0,1,0);
	protected Vector3 w = new Vector3(-1,0,0);
	
	public OrthonormalBasis(){
	}
	
	public OrthonormalBasis(Vector3 u,Vector3 v,Vector3 w){
		this.u = u;
		this.v = v;
		this.w = w;
	}
	
	public void set(Vector3 u, Vector3 v, Vector3 w) {
		this.u = u;
		this.v = v;
		this.w = w;
	}
	
	//Takes in the projection normal (-view direction) vector
	//and the up vector and computes an orthonormal basis, then
	//stores it in this OrthonormalBasis.
	public void compute(Vector3 projNormal, Vector3 up){
		w = new Vector3(projNormal.x,projNormal.y,projNormal.z);
		w.normalize();
		
		u.cross(up, w);
		u.normalize();
		
		v.cross(w, u);
		v.normalize();
		
	}
	
}
